//
//  FontViewController.swift
//  HHSwift
//
//  Created by 华宏 on 2020/2/15.
//  Copyright © 2020 huahong. All rights reserved.
//



/**
 * 1.导入资源文件TTF
 * 2.在info.plist中设置Fonts provided by application
 * 3.使用:UIFont(name: "FZLanTingHeiS-L-GB", size: 18)
 */
import UIKit

class FontViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        title = "字体";
        
        
        view.addSubview(self.tableView)
      
        
    }
    

    lazy var tableView: UITableView = {
        let tableView = UITableView(frame: self.view.bounds, style: .plain)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "tableIdentifier")
        return tableView
    }()

}

extension FontViewController:UITableViewDelegate,UITableViewDataSource{
   
    // MARK: UITableViewDataSource

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return UIFont.familyNames.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "tableIdentifier", for: indexPath)
        cell.accessoryType = .disclosureIndicator
        
        let familyName = UIFont.familyNames[indexPath.row]
        cell.textLabel?.font = UIFont(name: familyName, size: 15)
        cell.textLabel?.text = familyName
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      
        //        FZLanTingHeiS-DB-GB
        //        FZLanTingHeiS-L-GB
        let familyName = UIFont.familyNames[indexPath.row]
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font:UIFont(name: familyName, size: 18)!]
        print("familyName:\(familyName)")

    }
}
